package br.com.afi.encoding_converter.console.interpreter;

import java.text.MessageFormat;
import java.util.Map;

import br.com.afi.encoding_converter.Command;
import br.com.afi.pattern.interpreter.expression.AbstractProgressiveResultExpression;

/**
 * Expressão que representa um comando simples.
 * 
 * @author André de Fontana Ignacio
 * @version 1.0
 */
public class SimpleCommandExpression extends AbstractProgressiveResultExpression{
	private String str;
	private static final String DEFAULT_SYSTEM_CHARSET = "d";
	private static final String RECURSIVE_FILE_FILTER = "r";
	private static final String VERBOSE = "v";
	public static final String REGEX = MessageFormat.format("-({0}|{1}|{2})", DEFAULT_SYSTEM_CHARSET, RECURSIVE_FILE_FILTER, VERBOSE );
	
	/**
	 * Construtor
	 * 
	 * @param str String
	 * @param command Objeto que armazena os dados interpretados
	 */
	public SimpleCommandExpression( String str, Command command )
	{
		super();
		this.str = str;
		setResult( command );
	}
	
	@Override
	public Object interpret(Map<String, Object> variables ) {
		final Command command = getResult( Command.class );
		if( DEFAULT_SYSTEM_CHARSET.equals( str ) )
		{
			command.setShowDefaultSystemCharset( true );
		}
		else if( RECURSIVE_FILE_FILTER.equals( str ) )
		{
			command.setRecursiveFileFilter( true );
		}
		else if( VERBOSE.equals( str ) )
		{
			command.setVerbose( true );
		}
		return command;
	}

	@Override
	public String toString() {
		return MessageFormat.format("str={0}", str);
	}	
}
